Lazy neighborhood filter kernel compilation - #1708
Conversation
ASV BenchmarkingBenchmark Comparison ResultsBenchmarks that have improved:
Benchmarks that have stayed the same:
Benchmarks that have got worse:
|
Sevans711
left a comment
There was a problem hiding this comment.
Thank you looking into this! Assuming you wanted me to give an initial review now because you requested review, but not 100% sure since it is still marked as draft.
The regression test is clever, and I confirmed it crashes on main. This should be one good way to guard against import uxarray slowdowns in the future!
I left inline comments about the caching. Basically, it feels strange to me to use functools.cache in this situation, and I think it leads to some more-complicated-than-necessary code logic at the kernel call sites. I think it would be easier to maintain/understand quickly in the future if using a single cache which directly contains the cached kernels themselves, instead of caching on a per-function basis. That might also help with introspection/debugging later if you ever want to quickly check which kernels have been compiled so far. For example, there could even be a test which asserts _NUMBA_KERNELS is empty after import uxarray.
|
pre-commit.ci autofix |
Sevans711
left a comment
There was a problem hiding this comment.
After the factory pattern rework in defa8d6, I am happy with how this looks. The _make_kernel function itself looks a bit complicated but the docstring and comments clearly explain what is happening, and now it actually returns "a kernel function" instead of returning "a kernel factory which must be called to get the kernel function" so the way to use it is aligned with my intuitions based on the function names and documentation. I recommend merging to main!
erogluorhan
left a comment
There was a problem hiding this comment.
This looks good to me; thanks for the fixes!
Closes #1706
Overview
This PR should solve an issue introduced with PR #941, wherein the neighborhood filter gufunc-based kernels would compile eagerly, forcing a major slowdown of basic
import uxarrayimports, as well as creating threadpools that would eventually block safe forking that is needed in PR #1700.The idea is to have lazy compilation of gufuncs introduced with neighborhood filters for performant reductions. This prevents the otherwise eager compilation of every one of these kernels upon
import uxarray.Combined, this PR and PR #1700 can bring the total benchmark suit runtime down to about half of the pre-neighborhood filters runtime of ~40min, yielding about 20min without neighborhood filter benchmarks and 26-40ish minutes with them.
On its own, this PR can at least mitigate some of the benchmark performance regression, on the order of about 30-50% or so.
PR Checklist
General
Testing & Benchmarking
Documentation
AI Disclosure
AI Usage: Claude Opus 5